class User < ActiveRecord::Base

# Attribute names to display for errors
# --------------------------------

HUMANIZED_ATTRIBUTES = {
	:first_name => 			"First name",
	:middle_initial => 		"Middle initial",
	:last_name => 			"Last name",
	:univ_id => 			"University ID",
	:user_type => 			"User type",
	:email => 				"Email address",
	:perm_phone => 			"Permanent phone number",
	:campus_phone => 		"Campus phone number",
	:perm_address => 		"Permanent address",
	:perm_city => 			"City",
	:perm_state => 			"State",
	:perm_zip => 			"Zip code",
	:ta_curr_major  => 		"Current Major",
	:ta_entry_semester => 	"Entry semester",
	:ta_entry_year => 		"Entry year",
	:ta_app_type => 		"Application type (PhD or MS)",
	:ta_position => 		"Application position (full-time or part-time)",
	:ta_semester => 		"Application semester",
	:ta_year => 			"Application year",
	:currently_ta => 		"Current TA status",
	:ta_curr_course => 		"Current TA course",
	:ta_curr_instructor => 	"Current TA instructor",
	:ta_experience_1 => 	"Previous TA experience 1",
	:ta_experience_2 => 	"Previous TA experience 2",
	:ta_experience_3 => 	"Previous TA experience 3",
	:ta_experience_4 => 	"Previous TA experience 4",
	:ta_experience_5 => 	"Previous TA experience 5",
	:ta_pass_mei => 		"Passed MEI",
	:ta_curr_umei => 		"Currently taking UMEI",
	:ta_ms_degree => 		"Has MS degree",
	:ta_course_request_1 => "Primary course request (1)",
	:ta_course_request_2 => "Secondary course request (2)",
	:ta_course_request_3 => "Tertiary course request (3)",
	:ta_additional_info => 	"Additonal Information",
	:ta_signature => 		"Signature"
}
def self.human_attribute_name(attr)
	HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end


# Validation for TA Applications 
# --------------------------------

#Validation				#symbol	var			#regex restrictions				#condition							#error message to output (prepended with humanized name)
validates_presence_of 	:first_name, 																			:message => "is missing, this is a required field"
validates_format_of 	:middle_initial, 	:with => /^([A-Za-z])?$/,											:message => "is not valid, it must be a single character"
validates_presence_of 	:last_name, 																			:message => "is missing, this is a required field"
validates_format_of 	:univ_id, 			:with => /^\d{9}$/, 												:message => "is not a valid 9-digit number"
#user_type 				this needs to be generated by the system
#validates_format_of 	:email, 			:with => /\w@\w.\w/, 												:message => "is not valid, must be in format student@example.domain"
validates_format_of 	:email, 			:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/, 				:message => "is not valid, it must be in format student@example.domain"
validates_format_of 	:perm_phone, 		:with => /^(\d{3}-\d{3}-\d{4})?$/, 									:message => "is not valid, it must be in format ###-###-####"
validates_format_of 	:campus_phone, 		:with => /^(\d{3}-\d{3}-\d{4})?$/,									:message => "is not valid, it must be in format ###-###-####"
validates_format_of 	:campus_phone, 		:with => /^\d{3}-\d{3}-\d{4}$/, 	:unless => :perm_phone?,		:message => "or Permanent phone number must be provided"
validates_presence_of 	:perm_address, 																			:message => "is missing, this is a required field"
validates_presence_of 	:perm_city, 																			:message => "is missing, this is a required field"
validates_format_of 	:perm_state, 		:with => /^[A-Za-z]{2}$/, 											:message => "is not valid, it must only be two characters"
validates_format_of 	:perm_zip, 			:with => /^\d{5}(-\d{4})?$/,										:message => "is not valid, it must be in format ##### or #####-####"

validates_presence_of 	:ta_curr_major, 																		:message => "is missing, this is a required field"
validates_presence_of 	:ta_entry_semester, 																	:message => "is missing, this is a required field"
validates_format_of 	:ta_entry_year, 	:with => /^\d{4}$/, 												:message => "is not a valid year"
validates_presence_of 	:ta_app_type, 																			:message => "(PhD or MS) is missing, this is a required field"
validates_presence_of 	:ta_position, 																			:message => "(full-time or part-time) is missing, this is a required field"
validates_presence_of 	:ta_semester, 																			:message => "is missing, this is a required field"
#validates_format_of 	:ta_year, 			:with => /^\d{4}$/, 												:message => "is not a valid year"
validates_inclusion_of 	:currently_ta, 		:in => [true, false],												:message => "is missing, this is a required field"
validates_format_of 	:ta_curr_course, 	:with => /^[A-Za-z]{4}\d{3}$/, 	:if => :currently_ta?, 				:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"
validates_presence_of 	:ta_curr_instructor, 								:if => :currently_ta?, 				:message => "is missing, this is a required field"

validates_format_of 	:ta_experience_1, 	:with => /^([A-Za-z]{4}\d{3})?$/, 									:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"
validates_format_of 	:ta_experience_2, 	:with => /^([A-Za-z]{4}\d{3})?$/, 									:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"
validates_format_of 	:ta_experience_3, 	:with => /^([A-Za-z]{4}\d{3})?$/, 									:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"
validates_format_of 	:ta_experience_4, 	:with => /^([A-Za-z]{4}\d{3})?$/, 									:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"
validates_format_of 	:ta_experience_5, 	:with => /^([A-Za-z]{4}\d{3})?$/, 									:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"

validates_format_of 	:ta_experience_2, 	:with => /^$/, 					:unless => :ta_experience_1?, 		:message => "is not valid without a first TA experience (1)"
validates_format_of 	:ta_experience_3, 	:with => /^$/, 					:unless => :ta_experience_1?, 		:message => "is not valid without a first TA experience (1)"
validates_format_of 	:ta_experience_3, 	:with => /^$/, 					:unless => :ta_experience_2?, 		:message => "is not valid without a second TA experience (2)"
validates_format_of 	:ta_experience_4, 	:with => /^$/, 					:unless => :ta_experience_1?, 		:message => "is not valid without a first TA experience (1)"
validates_format_of 	:ta_experience_4, 	:with => /^$/, 					:unless => :ta_experience_2?, 		:message => "is not valid without a second TA experience (2)"
validates_format_of 	:ta_experience_4, 	:with => /^$/, 					:unless => :ta_experience_3?, 		:message => "is not valid without a third TA experience (3)"
validates_format_of 	:ta_experience_5, 	:with => /^$/, 					:unless => :ta_experience_1?, 		:message => "is not valid without a first TA experience (1)"
validates_format_of 	:ta_experience_5, 	:with => /^$/, 					:unless => :ta_experience_2?, 		:message => "is not valid without a second TA experience (2)"
validates_format_of 	:ta_experience_5, 	:with => /^$/, 					:unless => :ta_experience_3?, 		:message => "is not valid without a third TA experience (3)"
validates_format_of 	:ta_experience_5, 	:with => /^$/, 					:unless => :ta_experience_4?, 		:message => "is not valid without a fourth TA experience (4)"

#ta_pass_mei			not required field
#ta_curr_umei			not required field
#ta_ms_degree			not required field

validates_format_of 	:ta_course_request_1, :with => /^(\d{3})?$/, 											:message => "is not a valid three (3) digit number"
validates_format_of 	:ta_course_request_2, :with => /^(\d{3})?$/, 											:message => "is not a valid three (3) digit number"
validates_format_of 	:ta_course_request_3, :with => /^(\d{3})?$/, 											:message => "is not a valid three (3) digit number"
validates_format_of 	:ta_course_request_2, :with => /^$/, 				:unless => :ta_course_request_1?, 	:message => "cannot be requested without a primary course request (1)"
validates_format_of 	:ta_course_request_3, :with => /^$/, 				:unless => :ta_course_request_1?, 	:message => "cannot be requested without a primary course request (1)"
validates_format_of 	:ta_course_request_3, :with => /^$/, 				:unless => :ta_course_request_2?, 	:message => "cannot be requested without a secondary course request (2)"

#ta_additional_info 	not required field
validates_presence_of 	:ta_signature, 																			:message => "is missing, this is a required field"

end